#pragma once
#include <iostream>
#include <mutex>
#include <memory>

template <typename T>
class Singleton
{
public:
    //删除拷贝构造
    Singleton(const Singleton<T> &other)=delete;
    //删除赋值构造
    Singleton<T> & operator=(const Singleton<T> &other)=delete;

    //返回单例对象智能指针
    static std::shared_ptr<T> GetInstance()
    {
        static std::once_flag flag;
        std::call_once(flag,[&](){
            _instance = std::shared_ptr<T>(new T());
        });
        return _instance;
    }



protected:
    Singleton()=default;
    ~Singleton()=default;
    static std::shared_ptr<T> _instance;

};
template <typename T>
std::shared_ptr<T> Singleton<T>::_instance = nullptr;
